package image_pull

import (
	link "bridge/link_docker"
	"context"
	"fmt"
	"github.com/docker/docker/api/types"
	"net/http"
)

func Image_pull(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	r.ParseForm()
	name := r.Form["image_name"]
	cli := link.Client()
	resp, err := cli.ImagePull(context.Background(), name[0], types.ImagePullOptions{})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
	fmt.Fprint(w, "sess")
}

func Image_delete(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	r.ParseForm()
	name := r.Form["image_name"]
	cli := link.Client()
	resp, err := cli.ImageRemove(context.Background(), name[0], types.ImageRemoveOptions{})
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
	fmt.Fprint(w, "sess")
}
